<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="../../common/taglibs.jsp"%>
<%@include file="../common/header_easyui.jsp" %>
<script language="javascript">
    $(document).ready(function () {
        jQuery("#contractGrid").jqGrid({
            url:'${ctx}/contract/grid.do',
            datatype: "json",
            colNames:["ID","项目","合同名称","合同代码","甲方","乙方","翻译价格(元/千字符)","专业技术费","加急费(元)","排版费(元)","预付款(元)","总金额","是否生效","操作"],
            colModel:[
				{name:'id',index:'id',width:80,align:"center",sortable:false,hidden:true},
				{name:'project.name',index:'project.name',width:80,align:"center",sortable:false},
				{name:'name',index:'name',width:80,align:"center",sortable:false},
				{name:'code',index:'code',width:80,align:"center",sortable:false},
				{name:'firstParty.name',index:'firstParty.name',width:80,align:"center",sortable:false},
				{name:'secondParty.name',index:'secondParty.name',width:140,align:"center",sortable:false},
				{name:'price',index:'price',width:120,align:"center",sortable:false},
				{name:'professionalFee',index:'professionalFee',width:70,align:"center",sortable:false},
				{name:'urgentFee',index:'urgentFee',width:70,align:"center",sortable:false},
				{name:'typesettingFee',index:'typesettingFee',width:70,align:"center",sortable:false},
				{name:'advancePayment',index:'advancePayment',width:80,align:"center",sortable:false},
				{name:'moneyAmount',index:'moneyAmount',width:80,align:"center",sortable:false},
				{name:'isValid',index:'isValid',width:80,align:"center",sortable:false,formatter:validFormat},
                {name:'operation',index:'Id',width:80,align:"center",sortable:false}
            ],
            rowNum:15,
            autowidth :true, // 宽度自适应父窗口宽度
            mtype:"POST", // POST GET
            prmNames:{rows:"pageSize", sort:"orderBy", order:"order"}, // 设置翻页、排序参数
            rowList:[15,30,50],
            pager: '#pageContractGrid',
            jsonReader: { repeatitems : false },
            shrinkToFit: true,
//            caption: "合同列表",
//            multiselect: true,
            rownumbers:true,
            height: 330,
            gridComplete:function(){  //在此事件中循环为每一行添加修改和删除链接
                var ids=jQuery("#contractGrid").jqGrid('getDataIDs');
                for(var i=0; i<ids.length; i++){
                    var id=ids[i];
					var operation = "<a href='#' style='color:#f60' onclick='doView(" + id + ")'>查看</a>&nbsp;";
                    operation = "<a href='#' style='color:#f60' onclick='doEdit(" + id + ")'>修改</a>&nbsp;";  //这里的onclick就是调用了上面的javascript函数 Modify(id)
                    operation += "<a href='${ctx}/contract/export.do?id="+id+"' style='color:#f60' >导出</a>";  //这里的onclick就是调用了上面的javascript函数 Modify(id)
                    operation += "&nbsp;<a href='#'  style='color:#f60' onclick='doDelete(" + id + ")' >删除</a>";
                    jQuery("#contractGrid").jqGrid('setRowData', ids[i], { operation: operation});
                }
            }
        });

        jQuery("#contractGrid").jqGrid('navGrid','#pageContractGrid',{edit:false,add:false,del:false,search:false});

        setGridWidth = function (width){
            jQuery("#contractGrid").setGridWidth(width, true);
        };


//        JORegion.showAll();

        /**
         * 进行校核绑定
         */
        $('#contractForm input').each(function () {
            if ($(this).attr('required') || $(this).attr('validType')) {
                $(this).validatebox();
            }
        });
    });


	function doView(id) {
        openWindow("contractWindow", "查看", "${ctx}/contract/view.do?id=" + id, true, "contractGrid",800,440);
    }

	function doAdd(parentId) {
        openWindow("contractWindow", "新增", "${ctx}/contract/init.do", true, "contractGrid",800,550);
    }


    /**
     *
     * @param id
     */
    function doEdit(id) {
        openWindow("contractWindow", "编辑", "${ctx}/contract/init.do?id=" + id, true, "contractGrid",800,550);
    }

    function doExport(id) {
        window.href = "${ctx}/contract/export.do?id=" + id ;
    }

    function doDelete(id) {
        doGridDelete("${ctx}/contract/delete.do?id=" + id, "contractGrid");
    }
</script>

<body class="easyui-layout" style="overflow-y: hidden" scroll="no">
    <div region="center" title="合同列表" style="width:100%; height:100%; background:#fafafa;overflow-x: hidden; overflow-y: auto;">
        <%--<div id="jo_region_001" title="查询条件" divId="effect1" style="width: 100%">--%>
            <div id="effect1">
                <form id="contractForm" action="">
                    <table width="100%">
                        <input type="hidden" value="" id="treeId" name="treeId" op="like" entity="t"/>  
						<tr>
                            <td width="8%" nowrap="nowrap" align="left">
                                项目:
                                <input type="text"
                                       class="easyui-combobox"
                                       name="project"
                                       url="${ctx}/project/getProjects.do"
                                       valueField="id"
                                       textField="name"
                                       panelHeight="auto"
                                       op="eq" entity="t" isCapital="false" dtype="String"  style="width: 120px"
                                      />&nbsp;
                            </td>
                            <td width="8%" nowrap="nowrap" align="left">
                                合同名称:
                                <input type="text" id="name" name="name" value="" class="title_input"
                                       op="like" entity="t" isCapital="false" dtype="String"  style="width: 120px"/>
                            </td>
                            <td width="8%" nowrap="nowrap" align="left">
                                合同编号:
                                <input type="text" id="code" name="code" value="" class="title_input"
                                       op="like" entity="t" isCapital="false" dtype="String"  style="width: 120px"/>
                            </td>
                            <td width="8%" nowrap="nowrap" align="left">
                                甲方:
                                <input  type="text" name="name"  class="input_table" id="firstPartyName"  op="like" entity="t.firstParty" isCapital="false"  style="width: 120px"/>
                                <%--<input  type="hidden" name="firstParty"  id="firstParty" />--%>
                                <img src="${ctx}/skin/icons/edit_add.png" id="popTree" onclick="new PopTree({url:'${ctx}/contract/getSecond.do',targetValueId:'firstPartyName',onlyLeaf:true});">
                            </td>
						    <td>
                                <input type="button" value="查询" class="btn_Search" onclick="javascript:search('contractGrid','contractForm');"/>&nbsp;
                                <input type="button" value="新增" class="btn_Add" onClick="javascript:doAdd(null);"/>
                                <%--<a href="javascript:void(0);" onclick="toggleDiv('advanced_condition', '0')">高级查询</a>--%>
                            </td>
						</tr>
                    </table>
                    <div style="display: none;height:30px" id="advanced_condition">
                        
                    </div>
                </form>
            </div>
        <%--</div>--%>
        <table id="contractGrid"></table>
        <div id="pageContractGrid"></div>
        <div id="contractWindow"></div>
    </div>
</body>
</html>